//企业消息
import React, {Component} from 'react'
import {
    Text,
    Image,
    TouchableOpacity,
    Alert,
} from 'react-native';

import {fetchRequest} from '../../../util/fetch';
import {Cnews_Style as styles} from '../../../../styles';
import fmt from '../../../util/fmtDateUtil';

export default class Cnews_list extends Component {

    constructor(props) {
        super(props);
        this.state = {
            isR: 1,
            reload: 0,
        }
    }

    deleteMsg(msgId) {
        fetchRequest('xzMsg/deleteByIdMob.go', 'POST', {msgId: msgId}).then(ret => {
            if (ret.msg === 'ok') {
                this.props.deleteRow(msgId);
            }
        });
    }

    isRead(msgId) {
        fetchRequest('xzMsg/isReadByIdMob.go', 'POST', {msgId: msgId}).then(ret => {
            if (ret.msg === 'ok') {
                this.props.toRead(msgId);
            }
        });
    }

    componentDidUpdate() {
        if (this.props.msg.msgIsread === 1 && !this.state.isR) {
            this.setState({isR: 1});
        } else if (this.props.msg.msgIsread === 0 && this.state.isR) {
            this.setState({isR: 0});
        }
    }

    render() {
        return (
            <TouchableOpacity
                style={styles.newc_allin}
                activeOpacity={1}
                onPress={() => {
                    this.isRead(this.props.msg.msgId);
                    this.props.navigation.navigate('Newsin_c', {
                        msg: this.props.msg
                    });
                }}
            >
                <Image source={require('../../../img/app/boy.png')} style={styles.head}/>

                <Text style={styles.newc_main}>{this.props.msg.msgTital}</Text>

                {this.state.isR === 1 || <Text style={styles.newc_red}/>}

                <Text style={styles.newc_time}>{fmt(this.props.msg.msgTime, "yyyy-MM-dd")}</Text>
            </TouchableOpacity>

        )
    }
}

